#if SERVER
using ActorSystem;
using Net;
using Net.Share;

namespace AOIExample
{
    public partial class Robot : Actor
    {
        public float speed = 6;
        public float movementDistance = 20;
        private bool moving;
        private Vector3 start;
        private Vector3 destination;

        internal int roleCount;

        public override void OnStart()
        {
            Position = start = transform.Position;
        }

        public override void OnUpdate()
        {
            if (roleCount <= 0)
                return;
            if (moving)
            {
                if (Vector3.Distance(transform.Position, destination) <= 0.01f)
                {
                    moving = false;
                }
                else
                {
                    transform.Position = Vector3.MoveTowards(transform.Position, destination, speed * 0.033f);
                }
            }
            else
            {
                var circlePos = new Vector3(RandomHelper.Range(-1f, 1f), 0f, RandomHelper.Range(-1f, 1f));
                var dir = new Vector3(circlePos.x, 0, circlePos.y);
                var dest = transform.Position + dir * movementDistance;
                if (Vector3.Distance(start, dest) <= movementDistance)
                {
                    destination = dest;
                    moving = true;
                }
            }
        }
    }
}
#endif